package com.solution.admin.settings.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.solution.admin.product.service.ProductCategoryService;
import com.solution.admin.settings.service.SortService;
import com.solution.common.controller.BaseController;

/**
 * 排序控制层
 * @author: solin
 * @date: 2017年9月18日 下午11:58:17
 */
@RequestMapping("/sort")
@Controller
public class SortController extends BaseController{
	private Logger logger = LoggerFactory.getLogger(SortController.class);
	@Autowired
	private SortService sortService;
	@Autowired
	private ProductCategoryService productCategoryService;
	
	/**
	 * @param request
	 * @return
	 * @author: solin
	 * @date: 2017年9月19日 上午12:01:51
	 */
	@RequestMapping("")
	@ResponseBody
	public Map<String, Object> sort(HttpServletRequest request, String direction, String tableName, long id, 
			String parentColumnName, Long parentId) {
		Map<String, Object> result = new HashMap<String, Object>();
		int res = 0;
		try {
			res = sortService.sort(direction, tableName, id, parentColumnName, parentId);
			if("eb_product_category".equals(tableName)) {
				productCategoryService.doReloadCategorySort();
			}
		} catch (Exception e) {
			handleException("排序失败", logger, e);
		}
		result.put("code", res);
		return result;
	}
}
